#include<bits/stdc++.h>
using namespace std;
#define mk(x,y) make_pair((x),(y))
int n,m;
pair<int,int> change[]={{1,0},{-1,0},{0,1},{0,-1}};
bool pd(int x,int y){
    return x>=1&&x<=n&&y>=1&&y<=m;
}
void solve(){
    cin>>n>>m;
    queue<pair<int,int> > q;
    vector<vector<int> > v;
    vector<int> x,y;
    for(int i=1;i<=n;i++){
        vector<int> z;
        for(int j=1;j<=m;j++)z.push_back(0);
        v.push_back(z);
    }
    x.push_back(n+1>>1);
    y.push_back(m+1>>1);
    if(!(n&1))x.push_back(n+2>>1);
    if(!(m&1))y.push_back(m+2>>1);
    for(auto i:x)for(auto j:y){q.push(mk(i,j));v[i-1][j-1]=1;}
    while (q.size())
    {
        int xx=q.front().first,yy=q.front().second;
        q.pop();
        cout<<max(n-xx,xx-1)+max(m-yy,yy-1)<<" ";
        for(auto i:change)
            if(pd(i.first+xx,i.second+yy)&&(!v[i.first+xx-1][i.second+yy-1])){
                q.push(mk(i.first+xx,i.second+yy));
                v[i.first+xx-1][i.second+yy-1]=1;
            }
    }
    cout<<"\n";
}
int main () {
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)solve();
}